/*
 * @Author: FanWeiHua
 * @Date: 2021-05-14 17:31:19
 * @LastEditTime: 2021-07-14 17:03:57
 * @Description: 生产时构建
 */
'use strict';
const webpack = require('webpack');
const merge = require('webpack-merge');
// 压缩JS文件(webpack在构建时内置了该插件 如果需要对该插件进行配置 就需要安装 )
const TerserPlugin = require('terser-webpack-plugin');
const base = require('./webpack.base');
const util = require('./common/util');
const ESBuildPlugin = require('esbuild-webpack-plugin').default;
/**
 * webpack的自定义配置
 */
const defaultConfig = {
  webpackConfig: JSON.parse(process.env.webpackConfig)
};
// 转换对象的value为JSON_stringify
const config = util.getObj_value_JSON_stringify(defaultConfig);
const buildWebpackConfig = {
  plugins: [new webpack.DefinePlugin(config)],
  // 优化
  optimization: {
    minimize: true,
    minimizer: [
      new ESBuildPlugin()
      // new TerserPlugin()
    ]
  }
};
// 如果是打包测试环境
if (process.env.NODE_ENV === 'prod-dev' || process.env.NODE_ENV === 'local') {
  buildWebpackConfig.devtool = 'source-map';
}
module.exports = merge(base(), buildWebpackConfig);
